import flask
from concurrent.futures import ProcessPoolExecutor
import json

app = flask.Flask(__name__)


def is_prime(n: int):
    i = 2
    while i * i <= n:
        if n % i == 0: return False
        i += 1
    return True


@app.route("/is_prime/<numbers>")
def api_is_prime(numbers):
    number_list = [int(x) for x in numbers.split(",")]
    results = process_pool.map(is_prime, number_list)
    return json.dumps(dict(zip(number_list, results)))


# 下面直接运行会报错
if __name__ == '__main__':
    process_pool = ProcessPoolExecutor()
    app.run()